<template>
	<div>
		<el-checkbox style="margin-bottom: 10px;" v-model="select_all_permission" @change="handleALLPermission"
			label="全选" border>
		</el-checkbox>
		<el-checkbox-group v-model="c_permissions" @change="onSelectPermission">
			<el-table :data="permission_list" row-key="name" border :expand-row-keys="['角色管理']"
				:header-cell-style="{background:'#ccc', color: '#003366'}" :tree-props="{children: 'children'}">
				<el-table-column prop="meta.title" label="页面" width="200px">
					<template #default="scope">
						<el-checkbox :label="scope.row.name">{{ scope.row.meta.title }}</el-checkbox>
					</template>
				</el-table-column>
				<el-table-column label="操作">
					<template #default="scope">
						<div v-if="scope.row.showOperation">
							<el-checkbox v-if="scope.row.meta.add" :label="scope.row.meta.add">新增</el-checkbox>
							<el-checkbox v-if="scope.row.meta.del" :label="scope.row.meta.del">删除</el-checkbox>
							<el-checkbox v-if="scope.row.meta.edit" :label="scope.row.meta.edit">编辑</el-checkbox>
							<el-checkbox v-if="scope.row.meta.view" :label="scope.row.meta.view">查看</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'roomManage'" label="roomManage">房间管理
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'pushAddress'" label="pushAddress">推送地址
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'apkVersion'" label="apkVersion">查看固件版本
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'apkVersionSend'" label="apkVersionSend">
								发布版本
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'inOutLog'" label="inOutLog">进出记录
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'faceMoreOperation'"
								label="faceMoreOperation">更多操作
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'manageResetPwd'" label="manageResetPwd">
								重置密码
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'againPush'" label="againPush">重新推送
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation1 === 'pushFace'" label="pushFace">推送人脸
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation2 === 'infoDetail'" label="infoDetail">信息详情
							</el-checkbox>
							<el-checkbox v-if="scope.row.meta.operation2 === 'deviceMoreOperation'"
								label="deviceMoreOperation">更多操作
							</el-checkbox>
						</div>
					</template>
				</el-table-column>
			</el-table>
		</el-checkbox-group>
	</div>
</template>

<script>
	import permission from '@/router/dynamicRouter'

	export default {
		data() {
			return {
				c_permissions: this.permissions,
				permission_list: permission, // 获取辖区
				select_all_permission: false, // 全选辖区按钮
				all_permission: [
					'baiduaip', // 百度接口
					'baiduaipAdd',
					'baiduaipDel',
					'baiduaipEdit',
					'baiduaipGet',

					"project", // 项目
					"projectAdd",
					"projectGet",
					'projectEdit',

					"projectDel",

					'faceSwitch', // 人脸开关接口
					'faceSwitchAdd',
					'faceSwitchDel',
					'faceSwitchEdit',
					'faceSwitchGet',

					'areas', // 地区
					'areasAdd',
					'areasDel',
					'areasEdit',
					'areasGet',

					'address', // 地址
					'addressList',
					'addressAdd',
					'addressDel',
					'addressEdit',
					'addressGet',
					'roomManage',
					'infoDetail',
					'room', // 房间
					'roomAdd',
					'roomDel',
					'roomGet',
					'serviceDetail', // 地址信息服务详情
					'serviceDetailGet',
					'pushAddress',
					'maintenance', // 维护人员
					'maintenanceAdd',
					'maintenanceDel',
					'maintenanceGet',

					'packageManage', // 包
					'package',
					'apkAdd',
					'apkDel',
					'apkEdit',
					'apkGet',
					'apkVersion',
					'version', // 版本
					'apkVersionAdd',
					'apkVersionDel',
					'apkVersionGet',
					'apkVersionSend',

					'device', // 设备
					'deviceList',
					'deviceAdd',
					'deviceDel',
					'deviceEdit',
					'deviceGet',
					'inOutLog',
					'deviceMoreOperation',
					'command',
					'commandGet',
					'deviceOperation',

					'face', // 人脸
					'faceList', // 人脸列表
					'faceAdd',
					'faceDel',
					'faceEdit',
					'faceGet',
					'faceMoreOperation',
					'outInLogs', //  进出记录
					'outInLogsGet',
					'pushLogs', // 推送记录
					'pushLogsGet',
					'danger', // 可疑人脸
					'dangerGet',
					'pushFace',
					'faceOperation', // 人脸操作

					"permission", // 权限
					"roles",
					"roleGet",
					"roleAdd",
					"roleEdit",
					"roleDel",
					'manage',
					"manageGet",
					"manageAdd",
					"manageEdit",
					"manageDel",
					"manageResetPwd",

					"policeInterface", // 公安接口上传
					"information",
					'informationGet',
					"againPush",
					"policeInterfaceStatistical",

					"screen", // 屏保管理
					"screenSaver",
					'screenSaverAdd',
					"screenSaverDel",
					"screenSaverEdit",
					"screenSaverGet",
					"pushScreen"

				], // 选择全部辖区
			}
		},
		props: ['permissions'],
		watch: {
			permissions(val) {
				this.c_permissions = val;
				this.select_all_permission = this.c_permissions.length === this.all_permission.length;
			}
		},
		methods: {
			// 全选辖区
			handleALLPermission(val) {
				let self = this;
				console.log(val)
				self.c_permissions = val ? self.all_permission : [];
				self.$emit('getPermissions', {
					permissions: self.c_permissions
				})
			},
			// 不全选
			onSelectPermission(val) {
				let self = this;
				console.log(val)
				let checked_count = val.length;
				self.select_all_permission = checked_count === self.all_permission.length;
				self.$emit('getPermissions', {
					permissions: self.c_permissions
				})
				// self.selectAllStation = checked_count > 0 && checked_count < self.allStation.length;
			},
		}
	}
</script>

<style>
</style>
